﻿using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;

namespace Water.Data.Infrastructure
{
    static public class ConnectionHelper
    {
        public static ISessionFactory BuildSessionFactory()
        {
            return GetConfiguration().BuildSessionFactory();
        }

        public static FluentConfiguration GetConfiguration()
        {
            return Fluently.Configure()
                .Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("ConnStr")))
#if DEBUG
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<NhUnitOfWork>().ExportTo("d:\\dbm"))
#else
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<NhUnitOfWork>())
#endif
.ExposeConfiguration(x =>
                {
                    // x.SetInterceptor(new SqlStatementInterceptor());
                    //x.SetProperty("hbm2ddl.auto", "update");

                    x.SetProperty("cache.provider_class", "NHibernate.Cache.HashtableCacheProvider");
                    x.SetProperty("cache.use_second_level_cache", "true");
                    x.SetProperty("cache.use_query_cache", "true");

                });
        }
    }
}
